{__NOLAYOUT__}
<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link type="text/css" rel="stylesheet" href="/static/sys/css/login.css" />
    <link href="/static/plugins/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <title>后台登录</title>
</head>

<body class="login">
    <div class="login_m">
        <div class="login_logo">
            <img src="/static/sys/images/login_logo.png" title="logo" width="196" height="46">
        </div>
        <div class="login_boder">
            <div class="login_padding" id="login_model">
                <form id="login_form" method="POST">
                    <div class="username">
                        <h2>USERNAME</h2>
                        <label>
                            <input type="text" id="username" name="username" class="txt_input"
                                placeholder="your username">
                        </label>
                        <span class="uspan"></span>
                    </div>
                    <div class="password">
                        <h2>PASSWORD</h2>
                        <label>
                            <input type="password" id="userpwd" name="password" class="txt_input"
                                placeholder="the password">
                        </label>
                    </div>
                    <div class="verify">
                        <h2>CAPTCHA </h2>
                        <label>
                            <input type="text" id="verify" name="verify" class="verify_input" placeholder="the captcha">
                            <img src="/sys/verify" class="verify_img" width="120px" height="40px" title="captcha"
                                onclick="this.src='/sys/verify?tmp='+Math.random();">
                        </label>
                    </div>
                    <div class="forgot_password">
                        <h2>
                            <a href="javascript:void(0);" onclick="getPwd();">Forgot your password?</a>
                        </h2>
                        <span class="fspan"></span>
                    </div>
                    <div class="row cl">
                        <div class="formControls col-xs-8 col-xs-offset-3">
                            <input type="hidden" name="__token__" value="{:token()}" />
                            <button type="button" id="login"
                                class="btn btn-success radius size-L sub_button">&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;</button>
                        </div>
                    </div>
                </form>
            </div>
            <!--login_padding  Sign up end-->
        </div>
        <!--login_boder end-->
        <div class="copyrights">Collect from
            <a href="#">FYHS</a>
        </div>`
    </div>
    <!--login_m end-->

    <script type="text/javascript" src="/static/plugins/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/plugins/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="/static/plugins/layer/2.4/layer.js"></script>
    <script type="text/javascript">
        // 回车触发登录
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                $("#login").trigger("click");
            }
        });

        $('#login').css('opacity', 0.7).hover(function () {
            $(this).stop().fadeTo(650, 1);
        }, function () {
            $(this).stop().fadeTo(650, 0.7);
        });

        $(function () {
            // 后台登录
            $("#login").click(function () {
                var username = $("input[name='username']").val();
                var password = $("input[name='password']").val();
                var verify = $("input[name='verify']").val();
                var __token__ = $("input[name='__token__']").val();

                console.log(username);
                console.log(password);
                console.log(verify);
                console.log(__token__);

                if (!username) {
                    layer.alert('请输入用户名', {
                        icon: 2
                    }, function (index) {
                        layer.close(index);
                        $("input[name='username']").focus();
                    });
                    return false;
                }

                if (!password) {
                    layer.alert('请输入密码', {
                        icon: 2
                    }, function (index) {
                        layer.close(index);
                        $("input[name='password']").focus();
                    });
                    return false;
                }

                if (!verify) {
                    layer.alert('请输入验证码', {
                        icon: 2
                    }, function (index) {
                        layer.close(index);
                        $("input[name='verify']").focus();
                    });
                    return false;
                }

                $.ajax({
                    type: "post",
                    url: "{:url('/sys/login/dologin')}",
                    data: {
                        username: username,
                        password: password,
                        verify: verify,
                        __token__: __token__
                    },
                    dataType: "json",
                    beforeSend: function () {
                        loadIndex = layer.load();
                    },
                    success: function (res) {
                        if (res.code == 0) {
                            // sessionStorage.setItem('permissions', res.permissions);
                            layer.close(loadIndex);
                            // console.log(res.href);
                            // var restore_url = $("#restore_url").val();
                            window.location.href = "/sys/index/index.html";
                        } else {
                            layer.close(loadIndex);
                            layer.alert(res.msg, {
                                icon: 2
                            }, function (index) {
                                layer.close(index);
                                window.location.reload();
                                // $(".login-codeimg").attr("src", $(".login-codeimg").attr("src") + '?' + Math.random());
                            });
                        }
                    },
                    error: function (xhr) {
                        layer.close(loadIndex);
                        layer.alert('登录失败,请稍后重试', {
                            icon: 2
                        }, function (index) {
                            layer.close(index);
                            window.location.reload();
                        });
                    }
                });

            });
        });
        function getPwd() {
            $('.fspan').html("* 请联系网站管理员");
        }
    </script>

</body>

</html>